package columns

import (
	"GraduationProject/public/db"
	"GraduationProject/public/models"
	"GraduationProject/webserver/controllers/util"
	"github.com/gin-gonic/gin"
)

// todo: set columns
func Add(c *gin.Context) {
	_, err := util.AdminFilter(c)
	if err != nil {
		return
	}

	seedID, err := util.PostFormInt(c, "seed_id")
	if err != nil {
		return
	}

	value := c.PostForm("value")
	if value == "" {
		util.FailedResponse(c, 10001, "参数不能为空")
		return
	}

	if err := db.DB.Create(&models.Columns{
		SeedID: uint(seedID),
		Value:  value,
	}).Error; err != nil {
		util.FailedResponse(c, 10002, "添加排版失败")
		return
	}

	util.SuccessResponse(c)
}
